"""
input:
(a, (b, (c, (d, (e, (f))))))
output:
(f, (e, (d, (c, (b, (a))))))
"""

import re


def f3(l):
    contents = re.split(r'\(|, \(|\)+', l)[1:-1]
    return '(' + ', ('.join(reversed(contents)) + ')' * len(contents)


if __name__ == '__main__':
    teststr = ['(a, (b, (c, (d, (e, (f))))))',
               '(1, (2, (a, (b, (ee, (fgh, (0)))))))']
    for t in teststr:
        print(f3(t))
